unit SmallStruct.ActionView.TSSActionViewFactory;

interface

uses SmallStruct.Core.TSSObjectFactory,
  SmallStruct.ActionView;

type
  TSSActionViewFactory = class(TSSObjectFactory, ISSActionViewFactory)
  private
    function GetActionView(const AActionViewName: string): ISSActionView;
    procedure FreeActionView(AActionView: ISSActionView);
  end;

implementation

uses
  SmallStruct.Core,
  SmallStruct.ActionView.TSSActionView,
  SmallStruct.Configuration,
  SmallStruct.Controller,
  SmallStruct.View;

{ TSSActionViewFactory }

procedure TSSActionViewFactory.FreeActionView(AActionView: ISSActionView);
var
  View: ISSView;
begin
  View := AActionView.GetView;
  ((GetSystemObject.GetGlobalObjectTable as ISSObjectContainer).GetObject(SS_VIEW_FACTORY) as ISSViewFactory).FreeView(View);
  AActionView.ReleaseObjectInstance;
end;

function TSSActionViewFactory.GetActionView(const AActionViewName: string): ISSActionView;
var
  ActionViewContext: TSSActionViewContext;
  ConfigurationTable: ISSConfigurationTable;
  ActionViewConfiguration: ISSActionViewConfiguration;
begin
  Result := TSSActionView.Create(nil);

  ActionViewContext := TSSActionViewContext.Create(nil);
  ConfigurationTable := GetSystemObject.GetConfigurationTable as ISSConfigurationTable;
  ActionViewConfiguration := ConfigurationTable.QueryActionViewConfiguration(AActionViewName) as ISSActionViewConfiguration;
  ActionViewContext.SetConfiguration(ActionViewConfiguration);
  ActionViewContext.SetSystemObject(GetSystemObject);
  Result.SetContext(ActionViewContext);
  Result.SetView(((GetSystemObject.GetGlobalObjectTable as ISSObjectContainer).GetObject(SS_VIEW_FACTORY) as ISSViewFactory).GetView((ActionViewContext.GetConfiguration as ISSActionViewConfiguration).GetViewName));
  Result.InitObject;
end;

end.
